#ifndef _I2C_H
#define _I2C_H

#include "stm32f10x.h"
#include "sys.h"
//#include "./usart/usart.h"

#define USE_SOFTWARE_I2C
#ifdef USE_SOFTWARE_I2C

#define I2C_SCL_GPIO_PORT                  GPIOB
#define I2C_SCL_GPIO_PIN                   GPIO_Pin_10
#define I2C_SCL_GPIO_CLK_ENABLE()          do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); }while(0)

#define I2C_SDA_GPIO_PORT                  GPIOB
#define I2C_SDA_GPIO_PIN                   GPIO_Pin_11
#define I2C_SDA_GPIO_CLK_ENABLE()          do{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); }while(0)

#define SCL(x)			{GPIO_WriteBit(I2C_SCL_GPIO_PORT, I2C_SCL_GPIO_PIN, (BitAction)(x)); delay_us(5);}
#define SDA(x)			{GPIO_WriteBit(I2C_SDA_GPIO_PORT, I2C_SDA_GPIO_PIN, (BitAction)(x)); delay_us(5);}

void i2c_init(void);
uint8_t I2C_SDA_Read(void);
void I2C_Start(void);
void I2C_Stop(void);
void I2C_SendByte(uint8_t Byte);
uint8_t I2C_ReceiveByte(void);
void I2C_SendAck(uint8_t AckBit);
uint8_t I2C_ReceiveAck(void);
void Check_DeviceAddress(uint8_t Addr);
void I2C_WriteReg(uint8_t DeviceAddress, uint8_t RegAddress, uint8_t Data);
uint8_t I2C_ReadReg(uint8_t DeviceAddress, uint8_t RegAddress);

#else

#endif

#endif
